<?php
/**
 * Created by 橙橙同学.
 * User: 橙橙同学
 * Date: 2017/11/13
 * Time: 下午9:44
 */

class Wechat{

    protected static function getAccessToken($uniacid){
        $weiObj = WeAccount::create($uniacid);
        $token = $weiObj->fetch_token();
        return $token;
    }
    /**
     * 发送模板消息
     * @param $data
     * @return bool
     */
    public static function sendTemplateMessage($data)
    {
        $token   = self::getAccessToken();
        $url     = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $token;
        $request = http_post($url, $data);
        $req     = json_decode($request, true);
        if ($req['errcode'] == 0 && $req['errmsg'] == 'ok') {
            return true;
        } else {
            return false;
        }
    }

}